package lanou.giftsay_01.fragment.body;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.Toast;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import lanou.giftsay_01.R;
import lanou.giftsay_01.adapter.SelectGiftRvAdapter;
import lanou.giftsay_01.bean.SelectGiftAllBean;
import lanou.giftsay_01.tools.BaseFragment;
import lanou.giftsay_01.tools.NetTool;
import lanou.giftsay_01.tools.URLValues;

/**
 * Created by dllo on 16/8/26.
 */
public class SearchDanPinFragment extends BaseFragment {


    private RecyclerView rv;
    private SelectGiftRvAdapter selectGiftRvAdapter;

    public SearchDanPinFragment() {
        EventBus.getDefault().register(this);
    }

    @Override
    protected int setLayout() {

        return R.layout.searchdanpin_fragment;
    }

    @Override
    protected void initView() {
        rv = (RecyclerView) getView().findViewById(R.id.searchdanpin_rv);
        GridLayoutManager manager = new GridLayoutManager(mContext , 2);
        rv.setLayoutManager(manager);
        selectGiftRvAdapter = new SelectGiftRvAdapter(mContext);

    }

    @Override
    protected void initData() {

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getData(String data){
        NetTool netTool  = new NetTool();
        netTool.getNetData(URLValues.SEARCHHOTWORD+"&keyword="+data, SelectGiftAllBean.class, new NetTool.NetListener<SelectGiftAllBean>() {
            @Override
            public void onSuccess(SelectGiftAllBean selectGiftAllBean) {

                selectGiftRvAdapter.setSelectGiftAllBean(selectGiftAllBean);
                rv.setAdapter(selectGiftRvAdapter);
            }

            @Override
            public void onError(String errorMsg) {

            }
        });
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public  void getData(Integer a){
        selectGiftRvAdapter.setA(a);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
